[][src]Crate one_way_slot_map

An implementation of SlotMap with minimal restrictions on Keys and Values

This is an implementation of the slot map data structure similar to SlotMap with fewer restrictions and the ability to embed data inside the key objects. The "one-way" moniker for this crate comes from an implementation detail that prevent inserted values from being taken out again unless they are replaced with another instance. Values that are inserted can be referenced, and written to, but ownership of the values remains with the map even after the value is "removed".

The data structure uses fixed size chunks (like SlotMap's DenseSlotMap), so lookups require 2 steps of indirection.

Example Usage:

First create a Key Class with an embedded data type

use one_way_slot_map::*;

// Define a simple key with an embedded usize
define_key_type!(DemoKey<usize>);

// Or define a less-simple key with some derived traits
define_key_type!(TestKeyWithDerives<usize> : Copy + Clone + Debug);

//Then create a slot map and use the key for crud operations
let mut slot_map = SlotMap::new();

let key: DemoKey = slot_map.insert(0, "Demo!");
assert_eq!(Some(&"Demo!"), slot_map.get(&key));
let slot = slot_map.get_mut(&key).unwrap();
*slot = "Updated!";

assert_eq!(Some(&mut "Updated!"), slot_map.remove(&key));
assert_eq!(None, slot_map.get(&key));

Macros

define_key_type

Macro for creating a simple Key type for one-way slot maps. Key types can be created from scratch, but for most cases, this will produce what you want

Structs

SlotMap

Implementation of a slot map that limits the restrictions on slotted keys and values by preventing retrieval of original values without explicit replacement

SlotMapKeyData

Encapsulation of all the information that defines a slot in the slot map.

Constants

SLOT_MAP_CHUNK_SIZE

This tells the size of the chunks used by the slot map. I'm not sure why or how this would be used, but maybe it's good to know

Traits

SlotMapKey

Trait required for any type used as a slot map key.